<template>
  <div class="scoreLayer">
    <div class="center-box">
      <div class="star-box flex-between">
        <ul class="star-list">
          <li
            class="star-item"
            v-for="(v, i) in scoreList"
            :key="i"
            :class="v"
          ></li>
        </ul>
        <p class="star-num">{{ score }}分</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MStar",
  props: {
    score: {
      type: Number,
      validator: function (value) {
        if (value > 8) {
          console.warn("score number no more than ten");
        }
        return value >= 0 && value <= 8;
      },
      default: 0,
    },
  },
  computed: {
    scoreList() {
      let result = [];
      const score = Math.floor(this.score * 2) / 2;
      const integer = Math.floor(score);
      const hasDecimal = score % 1 !== 0;
      for (let i = 0; i < integer; i++) {
        result.push("full");
      }
      if (hasDecimal) result.push("half");
      for (let i = result.length; i < 5; i++) {
        result.push("empty");
      }
      return result;
    },
  },
  methods: {},
};
</script>
